package com.amit.hibernate;




import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

public class Lab40 {

	public static void main(String[] args) {
		
			try{
				SessionFactory sf=Chibernateutil.getFactory();
			
			Session session=sf.openSession();
			Transaction tx=session.beginTransaction();
			
			Query q=session.createQuery("from Contact c");
			q.setCacheable(true);
			List<Contact> list=q.list();
			
			for(Contact c:list)
			{
				System.out.println(c);
			}
			
			Criteria ct=session.createCriteria(Contact.class);
			ct.setCacheable(true);
			list=q.list();
			
			for(Contact c:list)
			{
				System.out.println(c);
			}
			
			
			tx.commit();
			
			Thread.currentThread().sleep(500);
			
			session.close();
		}catch(Exception e){
			e.printStackTrace();
		}
			}
}
